package com.javaking.clanteam.hvz;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.javaking.clanteam.hvz.sql.HVZUser;
import com.javaking.clanteam.hvz.sql.SQLRelay;
import com.javaking.clanteam.hvz.utils.BarcodeScanActivity;

public class LoginActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);
    }

    /**
	 * Calls the barcode scanner intent.
	 */
    public void scanBarcode(View v)
    {
    	Intent scanBarcodeActivity = new Intent(this,BarcodeScanActivity.class);
    	startActivityForResult(scanBarcodeActivity, 0);
    }
    
    /**
     * Will retrieve the barcode returned from our barcode scanner activity
     * and open the user panel for the appropriate user.
     */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    	String barcode = data.getStringExtra("barcode"); // Get the barcode
    	
    	// We want to return to the main view when this is done.
    	Intent userIntent = new Intent(getApplicationContext(), UserActivity.class);
    	
    	
		HVZUser user = SQLRelay.readUser(barcode); // read the user from our database based of the barcode.
		userIntent.putExtra("HVZUser_string", user.toString());
		startActivity(userIntent);	
		finish();	
    }
    
}
